﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace _905_sort_array_by_parity
{
    class Program
    {
        static void Main (string[] args)
        {
            int[] nums = new int[] { 3,1,2,4 };
            //int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            nums = new Solution ().SortArrayByParity (nums);
            for (int i = 0;i < nums.Length;i++)
            {
                Console.Write (nums[i] + " ");
            }
        }
    }

    public class Solution
    {
        public int[] SortArrayByParity (int[] A)
        {
            int[] nums = A.Where (t => t % 2 == 0).ToArray ();
            int[] obbs = A.Where (t => t % 2 == 1).ToArray ();

            nums.CopyTo (A, 0);
            obbs.CopyTo (A, nums.Length);

            return A;
        }
    }
}
